@Inject('$log', '$state', 'globalService', 'patrolService', 'ngDialogService')
class PatrolDetailController {
  constructor() {
    this.mapParams = {
      patrolUserName: '',
      patrolTimeStart: '',
      patrolTimeEnd: '',
      sortType: '',
      columnName: '',
    };
    this.patrolId = $state.params.id;
    this.$table = {
      fetchTimes: 0,
      isTableLoading: false,
      pagination: {
        ITEMS_PER_PAGE: 5,
        MAX_SIZE: 5,
        currentPage: 1,
        total: 0,
      },
    };
    this.isBeyond = false;
    this.$getPatrolProcess(this.patrolId);
    this.$getpatrolQuery(this.patrolId);
  }

  // 是否显示处理记录
  $isShowHandle() {
    this.isShowHandleBoolean = !this.isShowHandleBoolean;
  }

  $getPatrolProcess(patrolId) {
    this.$table.isTableLoading = true;
    this.patrolService
      .queryProcess({
        mapParams: { checkId: patrolId },
        page: this.$table.pagination.currentPage,
        size: this.$table.pagination.ITEMS_PER_PAGE,
      })
      .then((res) => {
        this.patrolProcessInfo = res.rows;
        this.$table.pagination.totalItems = res.total;
        this.$table.isTableLoading = false;
        if (res.total < 1) {
          this.$table.fetchTimes += 1;
        }
        if (res.total < 5) {
          this.isBeyond = true;
        }
      });
  }

  $getpatrolQuery(patrolId) {
    const mapParams = this.mapParams;
    this.patrolService
      .get(patrolId)
      .then((res) => {
        this.$log.debug(mapParams);
        this.patrolDetailInfo = res.data;
        const lineStr = this.patrolDetailInfo.recordStatus;
        if (lineStr === '1') {
          $('.active-timeline').css('width', '0%');
        } else if (lineStr === '2') {
          $('.active-timeline').css('width', '50%');
        } else if (lineStr === '3') {
          $('.active-timeline').css('width', '100%');
        }
        if (this.patrolDetailInfo.checkRectifyBean) {
          const redLineStr = this.patrolDetailInfo.checkRectifyBean.auditResult;
          if (redLineStr === '2') {
            $('.red-timeline').css('width', '50%');
          }
          this.patrolDetailInfo.checkRectifyBean.reasonAnalysisNames =
          this.patrolDetailInfo.checkRectifyBean.reasonAnalysisNames.join(',');
        }
      });
  }

  /*eslint-disable */
  // 获得src
  $getAvatarSrc(item) {
    if (item && item.filePath) {
      const src = `/${item.filePath}`;
      return src;
    }
  }

  // 获取巡查状态
  $getStatus(status) {
    switch (status) {
      case '1':
        return '待整改';
        break;
      case '2':
        return '待审核';
        break;
      case '3':
        return '已完成';
        break;
      default:
        return;
    }
  }

  // 文件预览
  $preview(archiveDetail) {
    let url = this.$state.href('documentPreview', {
      id: archiveDetail.id,
    });
    window.open(url,'_blank');
  }

  isShowMore() {
    this.isShowMoreInfo = !this.isShowMoreInfo;
  }
}

export default PatrolDetailController;
